import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;

import java.util.List;

public class RocketRun {
    public static void main(String[] args) throws Exception {


        //创建一个拉取消息的消费者对象

        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("wolfcode-consumer");

        //设置名字地址

        consumer.setNamesrvAddr("127.0.0.1:9876");

        //启动消费者

        consumer.start();

        PullResult pullResult = consumer.pull(new MessageQueue("03-pull-push", "broker-a", 0), "*", 0, 1);

        for (MessageExt messageExt : pullResult.getMsgFoundList()) {

            System.out.println("消费线程:" + Thread.currentThread().getName() + ",消息ID:" + messageExt.getMsgId() + ",消息内容:" + new String(messageExt.getBody()));

        }

        consumer.shutdown();


    }


//        //创建一个拉取消息的消费者对象
//        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("Producer-one");
//
//        //设置名字地址
//        consumer.setNamesrvAddr("192.168.1.88:9876");
//
//        //绑定消息的主题
//        consumer.subscribe("topic-one", "*");
//
//        consumer.setMessageModel(MessageModel.BROADCASTING);
//
//        //消费者监听处理消息方法
//        consumer.registerMessageListener(new MessageListenerConcurrently() {
//            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
//                for (MessageExt msg : msgs) {
//                    System.out.println("消费线程:" + Thread.currentThread().getName() + ",消息ID:" + msg.getMsgId() + ",消息内容:" + new String(msg.getBody()));
//                }
//                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
//            }
//        });
//
//        //启动消费者
//        consumer.start();

}



